package com.lagou.edu.ad.controller;

import com.lagou.edu.dto.PromotionAdDTO;
import com.lagou.edu.dto.PromotionSpaceDTO;
import com.lagou.edu.remote.AdRemoteService;
import com.lagou.edu.response.ResponseDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/ad")
public class AdController {

    @Autowired
    private AdRemoteService adRemoteService;

    @RequestMapping("/space/getAllspaces")
    public ResponseDTO getAllSpace(){
        List<PromotionSpaceDTO> spaceDTOList = adRemoteService.getAllSpaces();
        return ResponseDTO.success(spaceDTOList);

    }

    @PostMapping("/space/saveOrUpdateSpace")
    public ResponseDTO saveOrUpdateSpace(@RequestBody PromotionSpaceDTO spaceDTO){
        ResponseDTO responseDTO = adRemoteService.saveOrUpdateSpace(spaceDTO);
        return responseDTO;
    }

    @GetMapping("/space/getSpaceById")
    public ResponseDTO getSpaceById(@RequestParam("id")Integer id){
        PromotionSpaceDTO spaceDTO = adRemoteService.getSpaceById(id);
        return ResponseDTO.success(spaceDTO);
    }

    @GetMapping("/getAllAds")
    public ResponseDTO getAllAds(){
        List<PromotionAdDTO> adDTOList = adRemoteService.getAllAds();
        return ResponseDTO.success(adDTOList);
    }

}
